﻿using Guan.CMS.CommandProcessor.Command;
using Guan.CMS.Data.Infrastructure;
using Guan.CMS.Data.Repositories;
using Guan.CMS.Domain.Commands.Product;

namespace Guan.CMS.Domain.Handlers.Product
{
    public class RemoveProductsHandler : ICommandHandler<RemoveProductsCommand>
    {
        private readonly IProductRepository _productRepository;
        private readonly IUnitOfWork _unitOfWork;

        public RemoveProductsHandler(IProductRepository productRepository, IUnitOfWork unitOfWork)
        {
            this._productRepository = productRepository;
            this._unitOfWork = unitOfWork;
        }

        public ICommandResult Execute(RemoveProductsCommand command)
        {
            _productRepository.Delete(c => command.Ids.Contains(c.Id));
            _unitOfWork.Commit();
            return new CommandResult(true);
        }
    }
}